package com.springboot.springbootlogindemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springboot.springbootlogindemo.DTO.UserDTO;
import com.springboot.springbootlogindemo.domain.Follow;
import com.springboot.springbootlogindemo.domain.User;
import com.springboot.springbootlogindemo.domain.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FollowMapper extends BaseMapper<Follow> {


    @Select("SELECT * FROM user WHERE id IN (SELECT follow__user_id FROM follow WHERE user_id = #{userId})")
    List<User> findFollowedUsersByUserId(@Param("userId") Long userId);




    @Select("SELECT u.id, u.nick_name AS nickName, u.icon, u.phone, " +
            "ui.city, ui.introduce, ui.fans, ui.gender, ui.birthday, ui.level " +
            "FROM user u " +
            "JOIN userInfo ui ON u.id = ui.user_id " +
            "WHERE u.id = #{followId}")
    UserDTO findUserAndUserInfoByFollowId(@Param("followId") Long followId);

}
